﻿/*
 * Copyright (c) http://DesignBased.NET 
 * Author: http://t.163.com/Jeek 
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the 
 * Software  * without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 
 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
 * A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 * 
 */

using System.ComponentModel;
using Newtonsoft.Json;

namespace T163.Open.Api.WP7.Model
{
    /// <summary>
    /// 用户信息
    /// </summary>
    [JsonObject(MemberSerialization.OptIn)]
    public class Users : INotifyPropertyChanged
    {
        #region private field

        private string _id;
        private string _screenName;
        private string _name;
        private string _location;
        private string _description;
        private string _url;
        private string _profileImageUrl;
        private string _gender;
        private int _followersCount;
        private int _friendsCount;
        private int _favoritesCount;
        private int _statusesCount;
        private string _createdAt;
        private bool _blocking;
        private bool _following;
        private bool _followed_by;
        private bool _verified;
        private Statues _status;
        private string _reason;
        private string _realName;
        private string[] _sysTag;
        private string _icorp;
        private string _darenRec;
        private string[] _userTag;

        #endregion
        
        /// <summary>
        /// 用户id
        /// </summary>
        [JsonProperty("id")]
        public string ID
        {
            get
            {
                return _id;
            }
            set
            {
                if (value != _id)
                {
                    _id = value;
                    OnPropertyChanged("ID");
                }
            }
        }

        /// <summary>
        /// 个性网址
        /// </summary>
        [JsonProperty("screen_name")]
        public string ScreenName
        {
            get { return _screenName; }
            set
            {
                if (value != _screenName)
                {
                    _screenName = value;
                    OnPropertyChanged("ScreenName");
                }
            }
        }

        /// <summary>
        /// 昵称
        /// </summary>
        [JsonProperty("name")]
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                if (value != _name)
                {
                    _name = value;
                    OnPropertyChanged("Name");
                }
            }
        }

        /// <summary>
        /// 最近一条微博
        /// </summary>
        [JsonProperty("status")]
        public Statues Status
        {
            get
            {
                return _status;
            }
            set
            {
                if (value != _status)
                {
                    _status = value;
                    OnPropertyChanged("Status");
                }
            }
        }

        /// <summary>
        /// 地址
        /// </summary>
        [JsonProperty("location")]
        public string Location
        {
            get
            {
                return _location;
            }
            set
            {
                if (value != _location)
                {
                    _location = value;
                    OnPropertyChanged("Location");
                }
            }
        }

        /// <summary>
        /// 个人简介
        /// </summary>
        [JsonProperty("description")]
        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                if (value != _description)
                {
                    _description = value;
                    OnPropertyChanged("Description");
                }
            }
        }

        /// <summary>
        /// 个人网址
        /// </summary>
        [JsonProperty("url")]
        public string Url
        {
            get { return _url; }
            set
            {
                if (value != _url)
                {
                    _url = value;
                    OnPropertyChanged("Url");
                }
            }
        }

        /// <summary>
        /// 自定义图像
        /// </summary>
        [JsonProperty("profile_image_url")]
        public string ProfileImageUrl
        {
            get { return _profileImageUrl; }
            set
            {
                if (value != _profileImageUrl)
                {
                    _profileImageUrl = value;
                    OnPropertyChanged("ProfileImageUrl");
                }
            }
        }

        /// <summary>
        /// 性别 m f, sohu 1,0
        /// </summary>
        [JsonProperty("gender")]
        public string Gender
        {
            get { return _gender; }
            set
            {
                if (value != _gender)
                {
                    _gender = value;
                    OnPropertyChanged("Gender");
                }
            }
        }

        /// <summary>
        /// 粉丝数
        /// </summary>
        [JsonProperty("followers_count")]
        public int FollowersCount
        {
            get { return _followersCount; }
            set
            {
                if (value != _followersCount)
                {
                    _followersCount = value;
                    OnPropertyChanged("FollowersCount");
                }
            }
        }

        /// <summary>
        /// 关注数
        /// </summary>
        [JsonProperty("friends_count")]
        public int FriendsCount
        {
            get { return _friendsCount; }
            set
            {
                if (value != _friendsCount)
                {
                    _friendsCount = value;
                    OnPropertyChanged("FriendsCount");
                }
            }
        }

        /// <summary>
        /// 微博数
        /// </summary>
        [JsonProperty("statuses_count")]
        public int StatusesCount
        {
            get { return _statusesCount; }
            set
            {
                if (value != _statusesCount)
                {
                    _statusesCount = value;
                    OnPropertyChanged("StatusesCount");
                }
            }
        }

        /// <summary>
        /// 收藏数
        /// </summary>
        [JsonProperty("favourites_count")]
        public int FavoritesCount
        {
            get
            {
                return _favoritesCount;
            }
            set
            {
                if (value != _favoritesCount)
                {
                    _favoritesCount = value;
                    OnPropertyChanged("FavoritersCount");
                }
            }
        }

        /// <summary>
        /// 创建时间
        /// </summary>
        [JsonProperty("created_at")]
        public string CreatedAt
        {
            get { return _createdAt; }
            set
            {
                if (value != _createdAt)
                {
                    _createdAt = value;
                    OnPropertyChanged("CreatedAt");
                }
            }
        }

        /// <summary>
        /// 是否阻止
        /// </summary>
        [JsonProperty("blocking")]
        public bool Blocking
        {
            get
            {
                return _blocking;
            }
            set
            {
                if (value != _blocking)
                {
                    _blocking = value;
                    OnPropertyChanged("Blocking");
                }
            }
        }

        /// <summary>
        /// 是否 follow
        /// </summary>
        [JsonProperty("following")]
        public bool Following
        {
            get
            {
                return _following;
            }
            set
            {
                if (_following != value)
                {
                    _following = value;
                    OnPropertyChanged("Following");
                }
            }
        }

        /// <summary>
        /// 是否被 follow
        /// </summary>
        [JsonProperty("followed_by")]
        public bool FollowedBy
        {
            get
            {
                return _followed_by;
            }
            set
            {
                if (_followed_by != value)
                {
                    _followed_by = value;
                    OnPropertyChanged("FollowedBy");
                }
            }
        }

        /// <summary>
        /// 是否认证
        /// </summary>
        [JsonProperty("verified")]
        public bool Verified
        {
            get
            {
                return _verified;
            }
            set
            {
                if (_verified != value)
                {
                    _verified = value;
                    OnPropertyChanged("Verified");
                }
            }
        }

        [JsonProperty("realName")]
        public string RealName
        {
            get { return _realName; }
            set
            {
                if (_realName != value)
                {
                    _realName = value;
                    OnPropertyChanged("RealName");
                }
            }
        }

        [JsonProperty("sysTag")]
        public string[] SysTag
        {
            get { return _sysTag; }
            set
            {
                if (_sysTag != value)
                {
                    _sysTag = value;
                    OnPropertyChanged("SysTag");
                }
            }
        }

        [JsonProperty("icorp")]
        public string Icorp
        {
            get { return _icorp; }
            set
            {
                if (_icorp != value)
                {
                    _icorp = value;
                    OnPropertyChanged("Icorp");
                }
            }
        }

        [JsonProperty("darenRec")]
        public string DarenRec
        {
            get { return _darenRec; }
            set
            {
                if (_darenRec != value)
                {
                    _darenRec = value;
                    OnPropertyChanged("DarenRec");
                }
            }
        }

        [JsonProperty("userTag")]
        public string[] UserTag
        {
            get { return _userTag; }
            set
            {
                if (_userTag != value)
                {
                    _userTag = value;
                    OnPropertyChanged("UserTag");
                }
            }
        }

        /// <summary>
        /// 推荐原因
        /// </summary>
        [JsonProperty("reason")]
        public string Reason
        {
            get
            {
                return _reason;
            }
            set
            {
                _reason = value;
            }
        }

        public override bool Equals(object obj)
        {
            Users other = obj as Users;
            if (other == null)
                return false;

            return other.ID.Equals(this.ID);
        }

        public bool Equals(Users user)
        {
            if (user == null)
                return false;

            return this.ID.Equals(user.ID);
        }

        public override int GetHashCode()
        {
            return this.ID.GetHashCode();
        }

        public override string ToString()
        {
            return string.IsNullOrEmpty(this.ScreenName) ? string.Empty : this.ScreenName;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
